package com.pbase_test;

import com.pbase.tools.Logger;
import com.pbase.ui.page.BaseFragment;

import androidx.activity.OnBackPressedCallback;
import androidx.navigation.Navigation;

/**
 * User: psn
 * Date: 2021/12/30
 * 使用 Navigation 的应用基类留存参考
 */
public abstract class CurrentBaseFragment extends BaseFragment {
    protected abstract void onCreateBeforeCurrent();

    protected abstract void onCreateAfterCurrent();

    @Override
    protected void onCreateViewBefore() {
        onCreateAfterCurrent();
    }

    @Override
    protected void onCreateViewAfter() {
        requireActivity().getOnBackPressedDispatcher()
                .addCallback(new OnBackPressedCallback(true) {
                    @Override
                    public void handleOnBackPressed() {
                        //拦截返回事件
//            moveTaskToBack(true);
                        left();
                    }
                });
        onCreateBeforeCurrent();
    }

    public void left() {
        Logger.e(getClass(), "left NavigationViewFragment");
        Navigation.findNavController(this.getView()).navigateUp();
    }
}
